#include <algorithm>
#include <cstdio>

#define lowbit(x) ((x) & -(x))

const int N = 2e5 + 5;
int n, p, maxn;
int val[N], hash[N], dis[N], f[N];

inline int query(int pos) {
  int res = 0;
  while (pos) {
    res = std::max(res, val[pos]);
    pos -= lowbit(pos);
  }
  return res;
}

inline void modify(int pos, int v) {
  while (pos <= maxn) {
    val[pos] = std::max(val[pos], v);
    pos += lowbit(pos);
  }
}

struct Node {
  int x, y, id;
  bool typ;
  inline bool operator<(const Node &rhs) const {
    return x != rhs.x ? x < rhs.x : (y != rhs.x ? y < rhs.y : typ > rhs.typ);
  }
} node[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("P6007.in", "r", stdin);
  freopen("P6007.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &p);
  int x, y, cnt = 0;
  for (int i = 1; i <= p; ++i) {
    scanf("%d%d", &x, &y);
    node[++cnt] = Node{x, y, i, false};
    hash[cnt] = y;
    dis[i] -= x + y;
    scanf("%d%d", &x, &y);
    node[++cnt] = Node{x, y, i, true};
    hash[cnt] = y;
    dis[i] += x + y;
  }
  node[++cnt] = Node{n, n, 0, true};
  std::sort(hash + 1, hash + cnt + 1);
  maxn = std::unique(hash + 1, hash + cnt + 1) - hash - 1;
  for (int i = 1; i <= cnt; ++i) {
    node[i].y = std::lower_bound(hash + 1, hash + maxn + 1, node[i].y) - hash;
  }
  std::sort(node + 1, node + cnt);
  for (int i = 1; i < cnt; ++i) {
    if (!node[i].typ)
      f[node[i].id] = query(node[i].y) + dis[node[i].id];
    else
      modify(node[i].y, f[node[i].id]);
  }
  int ans = 0;
  for (int i = 1; i <= p; ++i) {
    if (node[i].x <= node[cnt].x && node[i].y < node[cnt].y) ans = std::max(ans, f[i]);
  }
  printf("%d", (n << 1) - ans);
  return 0;
}